package com.pms.controller;

import com.aliyun.oss.model.ResizeUdfApplicationRequest;
import com.pms.dto.RepairPageQueryDTO;
import com.pms.dto.RepairSaveDTO;
import com.pms.dto.RepairUpdateDTO;
import com.pms.result.PageResult;
import com.pms.result.Result;
import com.pms.service.RepairService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "报修相关接口")
@RestController
@RequestMapping("/repair")
@Slf4j
public class RepairController {

    @Autowired
    private RepairService repairService;

    @ApiOperation("新增报修")
    @PostMapping("/save")
    public Result<String> save(@RequestBody RepairSaveDTO repairSaveDTO){
        log.info("新增报修,{}",repairSaveDTO);
        repairService.save(repairSaveDTO);
        return Result.success();
    }

    @ApiOperation("报修分页查询")
    @GetMapping("/page")
    public Result<PageResult> page(RepairPageQueryDTO repairPageQueryDTO){
        log.info("报修分页查询,{}",repairPageQueryDTO);
        PageResult pageResult=repairService.page(repairPageQueryDTO);
        return Result.success(pageResult);
    }

    @ApiOperation("批量删除")
    @DeleteMapping("/delete")
    public Result<String> deleteBatch(@RequestParam List<Integer> ids){
        log.info("批量删除,{}",ids);
        repairService.deleteBatch(ids);
        return Result.success();
    }

    @ApiOperation("修改报修状态")
    @PutMapping("/update")
    public Result<String> update(@RequestBody RepairUpdateDTO repairUpdateDTO){
        log.info("修改报修状态,{}",repairUpdateDTO);
        repairService.update(repairUpdateDTO);
        return Result.success();
    }

}
